package spitfire.ksim.simulator;

/**
 * Encapsulation of the simulation duration of a simulator.
 * 
 * @see spitfire.ksim.simulator.KSimulator
 * 
 * @author Adam
 *
 */
public class KSimDuration {
	public static final long UNDEFINED = -1;
	private long startTime = UNDEFINED;
	private long endTime = UNDEFINED;
	
	public KSimDuration() {}
	
	public KSimDuration(long startTime, long endTime) {
		if (startTime < -1 || endTime < -1) {
			throw new RuntimeException("Invalid time");
		}
		this.setStartTime(startTime);
		this.setEndTime(endTime);
	}

	public void setStartTime(long startTime) {
		if (startTime < -1) {
			throw new RuntimeException("Invalid time");
		}
		this.startTime = startTime;
	}

	public long getStartTime() {
		return startTime;
	}

	public void setEndTime(long endTime) {
		if (endTime < -1) {
			throw new RuntimeException("Invalid time");
		}
		this.endTime = endTime;
	}

	public long getEndTime() {
		return endTime;
	}
	
	public void coverDuration(KSimDuration duration) {
		if (duration == null) {
			return;
		}
		if (startTime == UNDEFINED || duration.getStartTime() < startTime) {
			startTime = duration.getStartTime();
		}
		if (endTime == UNDEFINED || duration.getEndTime() > endTime) {
			endTime = duration.getEndTime();
		}
	}
}
